<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="学院" prop="xyId">
              <el-select v-model="queryParams.xyId" @change="handlelistPronj" placeholder="请选择">
                <el-option
                  v-for="item in proxyList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
            <!-- <el-form-item label="学校" prop="xxId">
              <el-select v-model="queryParams.xxId" placeholder="请选择">
                <el-option
                  v-for="item in proxxList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item> -->
            <el-form-item v-if="queryParams.xyId!=null" label="年级" prop="njId">
              <el-select v-model="queryParams.njId" @change="handlelistProzy" placeholder="请选择">
                <el-option
                  v-for="item in pronjList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item v-if="queryParams.njId!=null" label="专业" prop="zyId">
              <el-select v-model="queryParams.zyId" @change="handlelistProbj" placeholder="请选择">
                <el-option
                  v-for="item in prozyList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item v-if="queryParams.zyId!=null" label="班级" prop="clId">
              <el-select v-model="queryParams.clId" placeholder="请选择">
                <el-option
                  v-for="item in probjList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
           <el-form-item label="学生姓名" prop="stName">
        <el-input
          v-model="queryParams.stName"
          placeholder="请输入学生姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审批/批阅状态 " label-width="120px" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态 " clearable>
          <el-option
            v-for="dict in dict.type.pro_audit"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['project:proldzj:add']"
          style="font-size: 14px; color: blue;"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['project:proldzj:edit']"
          style="font-size: 14px; color: #3ac27c;"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['project:proldzj:remove']"
          style="font-size: 14px; color: #F56C6C;"
        >删除</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['project:proldzj:export']"
        >导出</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="proldzjList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="用户ID" align="center" prop="userId" /> -->
      <el-table-column label="学生姓名" align="center" prop="stName" />
      <!-- <el-table-column label="报告内容" align="center" prop="content" show-overflow-tooltip/>
      <el-table-column label="文件路径" align="center" prop="file" />
      <el-table-column label="文件类型" align="center" prop="fileType" />
      <el-table-column label="文件名称" align="center" prop="fileName" /> -->
      <el-table-column label="审批/批阅状态 " align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.pro_audit" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="得分" align="center" prop="new_count" />
      <!-- <el-table-column label="学期" align="center" prop="xq" /> -->
      <!-- <el-table-column label="评分" align="center" prop="markNumber" />
      <el-table-column label="评语/驳回原因" align="center" prop="markName" /> -->
      <el-table-column label="提交时间" align="center" prop="createTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
           <el-button
            size="mini"
            type="text"
            v-if="scope.row.status=='1'"
            @click="handlePass(scope.row)"
            v-hasPermi="['project:proldcg:edit']"
          >审核</el-button>
         <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            v-if="scope.row.status=='1'"
            @click="handleReject(scope.row)"
            v-hasPermi="['project:proldcg:edit']"
            style="font-size: 14px; color: #3ac27c;"
          >驳回</el-button>-->
          <el-button
            size="mini"
            type="text"
            @click="handleDetail(scope.row)"
            v-hasPermi="['project:proldzj:edit']"
            v-if="scope.row.status=='2' || scope.row.status=='3'"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleDelete(scope.row)"
            v-hasPermi="['project:proldzj:remove']"
          >删除</el-button>
          <el-button
            v-show="scope.row.status === '2'"
            size="mini"
            type="text"
            @click="handleRepulse(scope.row)"
            v-hasPermi="['project:proldzj:repulse']"
          >退回</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改劳动总结报告对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <!-- <el-form-item label="用户ID" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户ID" />
        </el-form-item> -->
        <el-form-item label="学生姓名">
          <el-input v-model="form.stName" placeholder="请输入学生姓名" readOnly/>
        </el-form-item>
        <el-form-item label="劳动说明">
          <el-input v-model="form.content" type="textarea" readOnly/>
          <!-- <editor v-model="form.content" :min-height="192"/> -->
        </el-form-item>
        <!--<el-form-item label="附件" prop="file">
          <file-upload v-model="form.file"/>
        </el-form-item>-->
        <el-form-item label="文件" prop="proFileList">
           <div v-for="item in form.proFileList" :key="item.id" class="fileImage">
               <img :src="item.file" alt="" v-if="item.fileType == 'image'" class="w-100 h-150 mr-100 one_overflow w-136 fs-140 col333 pointer" @click="download(item.file)"/>
             <video :src="item.file" controls v-if="item.fileType == 'video'"
                    class="w-100 h-150 mr-100 one_overflow w-136 fs-140 col333 pointer" @click="download(item.file)"/>
               <div class="one_overflow w-200 fs-14 col333 pointer" v-if="item.fileType == 'file'"  @click="download(item.file)">{{ item.fileName }}</div>

               </div>
        </el-form-item>
        <!-- <el-form-item label="文件名称" prop="fileName">
          <el-input v-model="form.fileName" placeholder="请输入文件名称" />
        </el-form-item> -->
        <!-- <el-form-item label="得分" prop="dfCount">
          <el-input-number v-model="form.dfCount" placeholder="请输入得分" />
        </el-form-item> -->
        <!-- <el-form-item label="学期" prop="xq">
          <el-input v-model="form.xq" placeholder="请输入学期" />
        </el-form-item> -->
         <el-form-item label="评分" v-if="form.status=='2'" prop="new_count">
          <el-input v-model="form.new_count" placeholder="请输入得分" readOnly/>
        </el-form-item>
        <el-form-item v-if="isUpdate=='2'" label="评分" prop="fsId" >
          <el-select v-model="form.fsId" placeholder="请选择">
            <el-option
              v-for="item in profsList"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="驳回理由"  prop="markName" v-if="form.status=='3'">
          <el-input v-model="form.markName" type="textarea" placeholder="请输入驳回理由"  :readOnly="isReadOnly"/>
        </el-form-item>
        <el-form-item label="评语"  prop="markName" v-if="form.status=='1'||form.status=='2'">
          <el-input v-model="form.markName" type="textarea" placeholder="请输入评语"  :readOnly="isReadOnly"/>
        </el-form-item>
        <el-dialog title = "驳回理由" :visible.sync="open4" :rules="rules" width="400px" height="1500px" append-to-body class="w-1000  mr-100 ml-100 mt-300 mb-100">
          <el-form-item label="驳回理由"  prop="remarkName">
          <el-input v-model="form.remarkName" type="textarea" placeholder="请输入内容" />
          </el-form-item>
          <el-button  type="primary"  @click="submitReject">确 定</el-button>
                  <el-button @click="cancelBh">取 消</el-button>
        </el-dialog>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <!--<el-button v-if="isUpdate=='2'" type="primary" @click="submitPass">通过</el-button>
        <el-button v-if="isUpdate=='3'" type="primary" @click="submitReject">驳回</el-button>-->
        <el-button v-if="isUpdate=='2'" type="primary" @click="submitPass">通过</el-button>
        <el-button v-if="isUpdate=='2'" type="primary" @click="rejectRemark">驳回</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

       <!-- 通过 -->
    <el-dialog :title="title" :visible.sync="open2" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="评分" prop="fsId">
          <el-select v-model="form.fsId" placeholder="请选择">
            <el-option
              v-for="item in profsList"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="评语" prop="markName">
          <el-input v-model="form.markName" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitPass">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
         <!-- 驳回 -->
    <el-dialog :title="title" :visible.sync="open3" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <!-- <el-form-item label="评分" prop="markNumber">
          <el-input-number v-model="form.markNumber" placeholder="请输入评分" />
        </el-form-item> -->
        <el-form-item label="驳回原因" prop="markName">
          <el-input v-model="form.markName" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitReject">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listProldzj, getProldzj, delProldzj, addProldzj, updateProldzj,listProldfs,pass,reject,listProxy,listProzy,listPronj,listProbj,listProxx,repulse } from "@/api/project/proldzj";

export default {
  name: "Proldzj",
  dicts: ['pro_ld_type', 'pro_audit'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 劳动总结报告表格数据
      proldzjList: [],
      //
      profsList:[],

      prozyList:[],
      proxyList:[],
      proxxList:[],
      pronjList:[],
      probjList:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      open2: false,
      open3: false,
      open4: false,
     // isDisabled: false,
      isReadOnly: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        content: null,
        file: null,
        fileType: null,
        fileName: null,
        status: null,
        dfCount: null,
        xq: null,
        markNumber: null,
        markName: null,
        xyId: null,
        xxId: null,
        zyId: null,
        njId: null,
        clId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        remarkName: [
          { required: true, message: "请输入内容", trigger: "blur" }
        ],
        // fsId:[{ required: true, message: "请选择评分", trigger: "change" }]
      },
      formTitle:{
        markName: '评语/驳回理由'
      },
      isUpdate: '',
    };
  },
  created() {
    this.getInit();
    this.getList();
  },
  methods: {
      download(url) {
        // window.location.href = url
        window.open(url);
      },
    getInit(){
      // listProldfs().then(response => {
      //   this.profsList = response.rows;
      // });
      //  listProxx().then(response => {
      //    this.proxxList = response.rows;
      //  });
      //  listProxy().then(response => {
      //    this.proxyList = response.rows;
      //  });
      //  listProzy().then(response => {
      //    this.prozyList = response.rows;
      //  });
      //  listPronj().then(response => {
      //    this.pronjList = response.rows;
      //  });
      //  listProbj().then(response => {
      //    this.probjList = response.rows;
      //  });
    },
    /** 查询劳动总结报告列表 */
    getList() {
      this.loading = true;
      listProldzj(this.queryParams).then(response => {
        this.proldzjList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.open2 = false;
      this.open3 = false;
      this.reset();
    },
    cancelBh(){
    this.open4 = false;
    this.form.markName = '';
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        content: null,
        file: null,
        fileType: null,
        fileName: null,
        createTime: null,
        status: null,
        dfCount: null,
        xq: null,
        markNumber: null,
        markName: null,
        xyId: null,
        xxId: null,
        zyId: null,
        njId: null,
        clId: null,
       // isDisabled: false,
        isReadOnly: false,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加劳动总结报告";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getProldzj(id).then(response => {
         if(response.data.proFileList.length>0){
        response.data.proFileList.forEach(item =>{
          item.file = process.env.VUE_APP_BASE_FILE + item.file;
        })
       }
        this.form = response.data;
        this.open = true;
        this.title = "修改劳动总结报告";
        this.isUpdate ='1'
      });
    },
        /**驳回 */
    handleReject(row) {
      this.reset();
      const id = row.id || this.ids
      getProldzj(id).then(response => {
        this.form = response.data;
        // this.form.status = '3'
        this.proLdUserList = response.data.proLdUserList;
        this.open = true;
        this.isUpdate ='3'
        this.formTitle.markName = "驳回原因";
        this.title = "驳回";
      });
    },

    handleRepulse(row) {
      this.$modal.confirm('是否确认打回劳动总结报告编号为"' + row.id + '"的数据项？').then(function() {
        return repulse(row);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("打回成功");
      }).catch(() => {});
    },

    /** 审核按钮操作 */
    handlePass(row) {
     // this.reset();
      const id = row.id || this.ids
      getProldzj(id).then(response => {
         if(response.data.proFileList.length>0){
        response.data.proFileList.forEach(item =>{
          item.file = process.env.VUE_APP_BASE_FILE + item.file;
        })
       }
        this.form = response.data;
        // this.form.status = '2'
        this.proLdUserList = response.data.proLdUserList;
        this.open = true;
        this.isUpdate ='2';
        //this.isDisabled = false;
        this.isReadOnly = false;
        this.formTitle.markName = "评语";
        this.title = "审核";
      });
    },
    /** 详情按钮操作 */
    handleDetail(row) {
      //this.reset();
      const id = row.id || this.ids
      getProldzj(id).then(response => {
        this.form = response.data;
        //this.form.status = '2';
        //this.isDisabled = true;
        this.isReadOnly = true;
        this.open = true;
        this.title = "劳动总结报告详情";
        this.isUpdate ='1';
      });
    },
      /**驳回-驳回理由 */
    rejectRemark() {
      this.open4 = true;
      this.form.markName = '';

     },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateProldzj(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addProldzj(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
         /** 提交按钮 */
    submitPass() {
          this.form.proLdUserList = this.proLdUserList;
          if (this.form.id != null) {
            pass(this.form).then(response => {
              this.$modal.msgSuccess("通过成功");
              this.open = false;
              this.getList();
            });
          }


    },
        /** 提交按钮 */
    submitReject() {
    this.form.markName = this.form.remarkName;
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.proLdUserList = this.proLdUserList;
          if (this.form.id != null) {
            reject(this.form).then(response => {
              this.$modal.msgSuccess("驳回成功");
              this.open = false;
              this.open4 = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除劳动总结报告编号为"' + ids + '"的数据项？').then(function() {
        return delProldzj(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('project/proldzj/export', {
        ...this.queryParams
      }, `proldzj_${new Date().getTime()}.xlsx`)
    },

    handlelistProxy(){
        listProxy(map).then(response => {
            this.proxyList = response.rows;
          });
        },
        handlelistPronj(value){
          console.log(value);
          var map = {};
          map.pId = value;
          listPronj(map).then(response => {
            this.pronjList = response.rows;
          });
          this.queryParams.njId = null
          this.queryParams.clId = null
          this.queryParams.zyId = null
        },
        handlelistProzy(value){
          console.log(value);

          var map = {};
          map.pId = value;
          listProzy(map).then(response => {
            this.prozyList = response.rows;
          });
          this.queryParams.clId = null
          this.queryParams.zyId = null
        },
        handlelistProbj(value){
          var map = {};
          map.pId = value;
          listProbj(map).then(response => {
            this.probjList = response.rows;
          });
          this.queryParams.clId = null
        },
  }
};
</script>

